package main

import (
	"flag"
	"fmt"
	"gitee.com/gam6it/SecToolkit/chaitin/xray"
	"log"
	"time"
)

func main() {
	var u, ei, token, ip string
	var projectId, templateId int
	flag.StringVar(&u, "url", "", "Xray URL地址")
	flag.StringVar(&ei, "ei", "", "引擎ID")
	flag.StringVar(&token, "token", "", "Token")
	flag.IntVar(&projectId, "pi", 1, "Project ID")
	flag.IntVar(&templateId, "ti", 1, "Template ID")
	flag.StringVar(&ip, "ip", "", "IP地址")
	flag.Parse()
	if ei == "" || u == "" || token == "" || ip == "" {
		log.Fatalf("输入不能为空！\n")
	}
	client := xray.NewClient(u, token, projectId, []string{ei}, 5*time.Minute)
	var bS = xray.NewSimpleBasicSetting("测试任务", fmt.Sprintf("X-Ray对Template[%d]创建扫描任务，目标：%s", templateId, ip), []string{ip}, []string{ei})
	var tS = xray.NewSimpleTaskSetting([]string{"1-65535"}, []string{}, false)
	var pO = xray.PlanOption{
		Active:         false,
		BasicSetting:   bS,
		TaskSetting:    tS,
		ExecRightNow:   false,
		TaskTemplateId: 0,
		TemplateSync:   false,
		Priority:       "",
		ProjectId:      0,
	}
	template, err := client.Template(templateId)
	if err != nil {
		log.Fatalln(err)
		return
	}
	plan, err := template.CreatePlan(pO)
	if err != nil {
		log.Fatalln(err)
		return
	}
	fmt.Printf("创建任务成功，任务ID：%d\n", plan.Id)
}
